package com.example.k8s.hello.bean.exam.vo;

import com.example.k8s.hello.bean.exam.constant.EdConstant;
import com.example.k8s.hello.bean.exam.entity.EdExamDetailEntity;
import com.example.k8s.hello.common.utils.CopyUtils;
import com.example.k8s.hello.bean.exam.entity.EdExamEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * 考试
 *
 * @author Mark sunlightcs@gmail.com
 */
@Data
@Accessors(chain = true)
@Schema(description = "考试vo")
public class EdExamVo extends EdExamEntity {

	@Schema(description = "考试项目列表")
	private List<EdExamDetailVo> details;

	public static EdExamVo build(EdExamEntity examEntity, List<EdExamDetailEntity> details) {
		EdExamVo vo = CopyUtils.copy(examEntity, EdExamVo.class);

		List<EdExamDetailVo> detailVos = details.stream().map(detail -> EdExamDetailVo.build(detail)).toList();

		return vo.setDetails(detailVos);
	}

	@Data
	public static class EdExamDetailVo {

		@Schema(description = "考试项目")
		private EdConstant.ExamItem item;

		@Schema(description = "考试项目名称")
		private String itemName;

		@Schema(description = "考试项目是否通过")
		private Boolean itemPass;

		public static EdExamDetailVo build(EdExamDetailEntity detail) {
			return CopyUtils.copy(detail, EdExamDetailVo.class).setItemName(detail.getItem().label);
		}
	}
}
